package com.telnetnz.ticketdesk.dao.wrapper;

import java.util.List;

import net.sf.ehcache.Cache;

import com.rockbb.common.dao.CacheManagerBean;
import com.telnetnz.ticketdesk.dao.entity.TicketToUserEntity;
import com.telnetnz.ticketdesk.dao.mapper.TicketToUserMapper;

public class TicketToUserWrap {

	public static final String[] ORDER_BY = { 
		"create_time"
	};
	public static final String[] ORDER = {"DESC", "ASC"};

	private TicketToUserMapper mapper;
	private Cache cache;

	public TicketToUserWrap() {}

	public TicketToUserWrap(
			TicketToUserMapper mapper, 
			CacheManagerBean cacheManagerBean) {
		this.mapper = mapper;
		this.cache = cacheManagerBean.get(mapper.getClass().getName());
	}

	public TicketToUserEntity selectByTicketIdAndUserId(long ticketId, long userId) {
		TicketToUserEntity entity = new TicketToUserEntity();
		entity.setTicketId(ticketId);
		entity.setUserId(userId);
		return mapper.selectByTicketIdAndUserId(entity);
	}

	public void insert(long ticketId, long userId)
	{
		if (ticketId == 0L || userId == 0L) return;

		TicketToUserEntity entity = new TicketToUserEntity();
		entity.initialize();
		entity.setTicketId(ticketId);
		entity.setUserId(userId);
		mapper.insert(entity);
	}

	public void deleteTicketToUser(long ticketId, long userId)
	{
		TicketToUserEntity entity = new TicketToUserEntity();
		entity.setTicketId(ticketId);
		entity.setUserId(userId);
		mapper.delete(entity);
	}

	public void deleteByTicketId(long ticketId)
	{
		mapper.deleteByTicketId(ticketId);
	}

	public void deleteByUserId(long userId)
	{
		mapper.deleteByUserId(userId);
	}

	public List<TicketToUserEntity> selectByUserId(long userId)
	{
		return mapper.selectByUserId(userId);
	}

	public List<TicketToUserEntity> selectByTicketId(long ticketId)
	{
		return mapper.selectByTicketId(ticketId);
	}

	public Cache getCache() 
	{
		return cache;
	}
}

